/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NewJInternalFrame.java
 *
 * Created on 19-jul-2010, 13:51:31
 */

package GestionMovimientos;

import administracion.BeanBinding.TblBeanBindingDetalleIngreso;
import administracion.delegate.GestionPedidosDelegate;
import administracion.helper.Listas;
import administracion.helper.Utiles_Fecha;
import administracion.helper.Utiles_MensajesDialogo;
import administracion.helper.Utiles_Tabla;
import administracion.helper.VerificarDatos;
import administracion.propiedades.Propiedades;
import com.jidesoft.hints.ListDataIntelliHints;
import java.awt.Frame;
import java.awt.event.KeyEvent;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JDialog;
import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;
import javax.swing.text.MaskFormatter;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;
import org.jdesktop.beansbinding.ELProperty;
import org.jdesktop.swingbinding.JTableBinding;
import org.jdesktop.swingbinding.SwingBindings;
import suministros.ejb30.TO.AlmacenTO;
import suministros.ejb30.TO.CentroCostoTO;
import suministros.ejb30.TO.DetalleOrdenTO;
import suministros.ejb30.TO.DetalleTransferenciaTO;
import suministros.ejb30.TO.NotaIngresoTO;
import suministros.ejb30.TO.OrdenTO;
import suministros.ejb30.TO.ProyectoTO;
import suministros.ejb30.TO.SubAlmacenTO;
import suministros.ejb30.TO.TipoTO;
import suministros.ejb30.TO.TransferenciaTO;
import suministros.ejb30.TO.UnidadOrganizativaTO;
import suministros.ejb30.TO.ZonaTO;
import suministros.ejb30.entity.CentroCosto;
import suministros.ejb30.entity.DetalleMovimiento;
import suministros.ejb30.entity.DetalleMovimientoPK;
import suministros.ejb30.entity.Movimiento;
import suministros.ejb30.entity.Orden;
import suministros.ejb30.entity.Parametros;
import suministros.ejb30.entity.Proyecto;
import suministros.ejb30.entity.Suministros;
import suministros.ejb30.entity.Tipo;
import suministros.ejb30.entity.Transferencia;
import suministros.ejb30.entity.UnidadOrganizativa;
import suministros.ejb30.helper.Utiles_Convertir;
import org.jdesktop.beansbinding.AbstractBindingListener;
import org.jdesktop.beansbinding.AutoBinding;
import org.jdesktop.beansbinding.Binding;
import org.jdesktop.beansbinding.BindingGroup;
import suministros.ejb30.TO.ComprobantePagoTO;
import suministros.ejb30.TO.EmpresaTO;
import suministros.ejb30.TO.ProveedorTO;
import suministros.ejb30.entity.DetalleMovimientoTemporal;
import suministros.ejb30.entity.Proveedor;
import suministros.ejb30.entity.TipoCambioDiario;

/**
 *
 * @author Diana
 */
public class jifIngresosAlmacen extends javax.swing.JInternalFrame {
    List<DetalleOrdenTO> detalles;
    private JTableBinding jTableBinding;
    List<NotaIngresoTO> detallesIngreso;
    List<DetalleOrdenTO> detallesOrden;
    List<ZonaTO> zonas;
    List<EmpresaTO> empresas;
    List<AlmacenTO> almacenes;
    List<SubAlmacenTO> subalmacenes;
    private MaskFormatter mascaraFechaIngreso;
    OrdenTO ordento;
    List listaTipos = null;
    String codIngreso=null;
    private ListDataIntelliHints intelliHintsCodigos;
    private ListDataIntelliHints intelliHintsProveedor;
    private Proveedor proveedor;
    private List<TblBeanBindingDetalleIngreso>  detallesdevolucion;
    TransferenciaTO transferencia;
    List<DetalleTransferenciaTO> detallestransferencia= new ArrayList<DetalleTransferenciaTO>();
    List listacodigo= new ArrayList();
    public int codigoTemporal=-1;
    public String serie;
    public String numero;
    private ListDataIntelliHints intelliHintsComprobantes;


    /** Creates new form NewJInternalFrame */
    public jifIngresosAlmacen() {
        if(Listas.getInventario()){
            Utiles_MensajesDialogo.mensajeAlerta("Hay un inventario iniciado \nNo se pueden realizar ingresos de almacen");
            this.dispose();
        }
        else{
            construirMascaras();
            initComponents();
            Parametros parametro=new Parametros();
            try {
                parametro = Listas.getParametrosID("SU1");
            } catch (Exception ex) {
                Logger.getLogger(jifIngresosAlmacen.class.getName()).log(Level.SEVERE, null, ex);
            }
            this.setTitle("SISTEMA INTEGRADO DE GESTION DE SUMINISTROS Y ALMACENES   " + "ANIO:"+parametro.getParam1()+ " - MES:"+parametro.getParam2());
            empresas = Listas.getEmpresas();
            
            this.llenarComboTipoDocumento();
            this.llenarComboTipoIngreso();
            this.llenarComboTipoMovimiento();
          
            this.llenarComboEmpresa();
            this.llenarComboZonas();
            this.llenarComboAlmacen();
            this.llenarComboSubAlmacen();
            this.llenarComboTipoMoneda();
            this.jcbAlmacen.setEnabled(false);
            this.jcbSubAlmacen.setEnabled(false);
            detalles= new  ArrayList<DetalleOrdenTO>();
            detallesdevolucion= new  ArrayList<TblBeanBindingDetalleIngreso>();
            detallesIngreso = new ArrayList<NotaIngresoTO>();
            detallesOrden= new ArrayList<DetalleOrdenTO>();
            detallestransferencia = new ArrayList<DetalleTransferenciaTO>();
            cargaHintsIndependientes();
            this.jcbEmpresa.setEnabled(false);
        }
       
    }
    private void buscarRazonSocial()
      {
        ProveedorTO pro;
        if (this.jtfRuc.getText().trim().length() < 1) {
              try { pro = (ProveedorTO)this.intelliHintsProveedor.getSelectedHint();
              } catch (NullPointerException ex) {
                pro = null;
              }
            }
        else {
          pro = Listas.getProveedorcodigo(this.jtfRuc.getText().trim());
        }
        if (pro == null) {
          Utiles_MensajesDialogo.mensajeError("El proveedor no existe!");
          this.jtfRuc.setText("");
          pro = null;
        }
        else {
          this.proveedor = Utiles_Convertir.convertirToProveedor_ProveedorTO(pro);
          this.jtfRuc.setText(pro.getRazon() + " - " + pro.getCodProveedor());
          this.jtfRuc.setText(pro.getCodProveedor());

        }

      }
    public void obtenerCodigos() throws Exception{
         List<TransferenciaTO>  codigos= new ArrayList<TransferenciaTO> ();
         codigos.clear();
         List<TransferenciaTO>  codigosTotal= new ArrayList<TransferenciaTO> ();
         codigosTotal.clear();
         if(this.jcbTipoIngreso.getSelectedIndex()>=0){
             if(this.jcbEmpresa.getSelectedIndex()>=0){
                    Tipo t=Utiles_Convertir.convertirToTipo_TipoTO((TipoTO)this.jcbTipoIngreso.getSelectedItem());
                    if(t.getDescripcionValor().toString().compareTo("COMPRA")==0){
                        codigos= GestionPedidosDelegate.getInstance().obtenerCodigos(1);

                    }
                    if(t.getDescripcionValor().toString().compareTo("TRANSFERENCIA")==0){
                         codigos= GestionPedidosDelegate.getInstance().obtenerCodigos(2);
                    }
                    for(TransferenciaTO dato: codigos){
                     boolean estado=false;
                     String  emp=empresas.get(this.jcbEmpresa.getSelectedIndex()).getCodigo();
                     if(emp.compareTo(dato.getEmpresa())==0){
                          estado=true;
                     }
                     if(estado){
                          for(int i=0; i<zonas.size(); i++){
                             if(zonas.get(i).getId_zona().compareTo(dato.getZona())==0){
                                codigosTotal.add(dato);
                              }
                          }
                 }
                }
                this.intelliHintsCodigos.setCompletionList(codigosTotal);   
       }
       else{
       Utiles_MensajesDialogo.mensajeFracaso("No se ha seleccionado una empresa");
      }
     }
      else{
       Utiles_MensajesDialogo.mensajeFracaso("No se ha seleccionado un tipo de Ingreso");
    }
    
}

     private void construirMascaras() {
    try {
      this.mascaraFechaIngreso = new MaskFormatter("##/##/####");
    } catch (ParseException ex) {
      Logger.getLogger(jifIngresosAlmacen.class.getName()).log(Level.SEVERE, null, ex);
      ex.printStackTrace();
    }
  }

     private void llenarComboTipoIngreso() {
        List listaTipos1 = null;
        List listaTipos_cbo1 = this.cboBeanBindingTipo1.getLista();
        listaTipos_cbo1.clear();
        try
        {
          listaTipos1 = Listas.getTipo_porTabla("tipo_ingreso");

          this.cboBeanBindingTipo1.setLista(listaTipos1);
          this.bindingGroup.bind();
          this.jcbTipoIngreso.updateUI();
          this.jcbTipoIngreso.setSelectedIndex(-1);
        } catch (Exception ex) {
          Utiles_MensajesDialogo.mensajeAlerta("Error al obtener Ingresos\n" + ex.getMessage());
          ex.printStackTrace();
          Logger.getLogger(jifIngresosAlmacen.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
      private void llenarComboTipoDocumento() {
        List listaTipos2 = null;
        List listaTipos_cbo2 = this.cboBeanBindingTipo2.getLista();
        listaTipos_cbo2.clear();
        try
        {
          listaTipos2 = Listas.getTipo_porTabla("tipo_documento");

          this.cboBeanBindingTipo2.setLista(listaTipos2);
          this.bindingGroup.bind();

        } catch (Exception ex) {
          Utiles_MensajesDialogo.mensajeAlerta("Error al obtener tipos documentos\n" + ex.getMessage());
          ex.printStackTrace();
          Logger.getLogger(jifIngresosAlmacen.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
      private void llenarComboTipoMoneda() {
        List listaTipos1 = null;
        List listaTipos_cbo1 = this.cboBeanBindingTipo4.getLista();
        listaTipos_cbo1.clear();
        try
        {
          listaTipos1 = Listas.getTipo_porTabla("Tipo_moneda");

          this.cboBeanBindingTipo4.setLista(listaTipos1);
          this.bindingGroup.bind();
          this.jcboMoneda.updateUI();
          this.jcboMoneda.setSelectedIndex(0);
        } catch (Exception ex) {
          Utiles_MensajesDialogo.mensajeAlerta("Error al obtener Tipos Monedas\n" + ex.getMessage());
          ex.printStackTrace();
          Logger.getLogger(jifIngresosAlmacen.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
      private void llenarComboTipoMovimiento() {

        List listaTipos_cbo = this.cboBeanBindingTipo3.getLista();
        listaTipos_cbo.clear();
        try
        {
         listaTipos = Listas.getTipo_porTabla("tipo_Movimiento");

        } catch (Exception ex) {
          Utiles_MensajesDialogo.mensajeAlerta("Error al obtener tipos documentos\n" + ex.getMessage());
          ex.printStackTrace();
          Logger.getLogger(jifIngresosAlmacen.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
       private void llenarComboEmpresa() {
        empresas = null;
        List listaPaises_cbo = this.cboBeanBindingEmpresa1.getLista();
        listaPaises_cbo.clear();
        try
        {
          
            
          empresas = Listas.getEmpresaPrincipal();
          this.cboBeanBindingEmpresa1.setLista(empresas);
          this.bindingGroup.bind();
          this.jcbEmpresa.updateUI();
          this.jcbEmpresa.setSelectedIndex(0);
        } catch (Exception ex) {
          Utiles_MensajesDialogo.mensajeAlerta("Error al obtener empresas\n" + ex.getMessage());
          ex.printStackTrace();
          Logger.getLogger(jifIngresosAlmacen.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
      private void llenarComboZonas() {
        zonas = null;
        List listaPaises_cbo = this.cboBeanBindingZona1.getLista();
        listaPaises_cbo.clear();
        try
        {
          zonas = Listas.getZonas();
          this.cboBeanBindingZona1.setLista(zonas);
          this.bindingGroup.bind();
          this.jcbZona.updateUI();
          this.jcbZona.setSelectedIndex(0);
        } catch (Exception ex) {
          Utiles_MensajesDialogo.mensajeAlerta("Error al obtener zonas\n" + ex.getMessage());
          ex.printStackTrace();
          Logger.getLogger(jifIngresosAlmacen.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
      private void llenarComboAlmacen() {
        almacenes = null;
        List listaPaises_cbo = this.cboBeanBindingAlmacen1.getLista();
        listaPaises_cbo.clear();
        try
        {
          almacenes = Listas.getAlmacenes();
          this.cboBeanBindingAlmacen1.setLista(almacenes);
          this.bindingGroup.bind();
          this.jcbAlmacen.updateUI();
          this.jcbAlmacen.setSelectedIndex(-1);
        } catch (Exception ex) {
          Utiles_MensajesDialogo.mensajeAlerta("Error al obtener almacenes\n" + ex.getMessage());
          ex.printStackTrace();
          Logger.getLogger(jifIngresosAlmacen.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
       private void llenarComboSubAlmacen() {
        subalmacenes = null;
        List listaPaises_cbo = this.cboBeanBindingSubAlmacen1.getLista();
        listaPaises_cbo.clear();
        try
        {
          subalmacenes = Listas.getSubalmacenes();
          this.cboBeanBindingSubAlmacen1.setLista(subalmacenes);
          this.bindingGroup.bind();
          this.jcbSubAlmacen.updateUI();
          this.jcbSubAlmacen.setSelectedIndex(-1);
        } catch (Exception ex) {
          Utiles_MensajesDialogo.mensajeAlerta("Error al obtener subalmacenes\n" + ex.getMessage());
          ex.printStackTrace();
          Logger.getLogger(jifIngresosAlmacen.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
      public List<NotaIngresoTO> convertirDetalles_Ingresos( List<DetalleOrdenTO> listadetalles){
           List<NotaIngresoTO> deIngreso= new ArrayList<NotaIngresoTO>();
          for(DetalleOrdenTO deta: listadetalles){
                 NotaIngresoTO ing= new NotaIngresoTO(deta.getNroOrden(), deta.getSuministro(), deta.getDescripcion(), deta.getDescripcionValor(),deta.getCantidad(), deta.getPrecio(), deta.getValor(), new BigDecimal(0));
                 deIngreso.add(ing);
             }
          return deIngreso;
      }


    private void obtenerOrdenCompra() {
    try
    {
      //obtenerDetallesIngreso();
      ordento= new OrdenTO();
      ordento = GestionPedidosDelegate.getInstance().obtenerDatosOrden(this.jtfOrden.getText().trim());
      if(ordento ==null){
          Utiles_MensajesDialogo.mensajeAlerta("No se ha encontrado la orden de compra\n Tiene que registrar la factura antes de\n ingresar suministros al almacen");
      }
      else{
          boolean estado=false;
          String  emp=empresas.get(this.jcbEmpresa.getSelectedIndex()).getCodigo();
          if(emp.compareTo(ordento.getEmpresa())==0){
                estado=true;
           }    
          if(estado){
 
              estado=false;
              for(int i=0; i<zonas.size(); i++){
                  if(zonas.get(i).getNom_zona().compareTo(ordento.getZona())==0){
                    estado=true;
                  }
              }
              if(estado)
              {
                  this.jcbEmpresa.setSelectedItem(this.obtenerEmpresa(ordento.getEmpresa()));
                  this.jcbZona.setSelectedItem(this.obtenerZona(ordento.getZona()));
                  this.jcbAlmacen.setSelectedItem(this.obtenerAlmacen(ordento.getAlmacen()));
                  this.jcbSubAlmacen.setSelectedItem(this.obtenerSubAlmacen(ordento.getSubAlmacen()));
                  //this.obtenerDetallesOrdenCompra();
                  this.jcbEmpresa.setEnabled(false);
                  this.jbtAceptar.setEnabled(true);
                  List<ComprobantePagoTO> lista= new ArrayList<ComprobantePagoTO>();
                  lista= GestionPedidosDelegate.getInstance().getDatosOrdenComprobante(this.jtfOrden.getText().trim());
                  this.intelliHintsComprobantes = new ListDataIntelliHints(this.jtfFactura, lista);
                 // this.jcbTipoIngreso.setEnabled(false);
              }
              else{
                 Utiles_MensajesDialogo.mensajeAlerta("La orden de compra no pertenece a la zona seleccionada");
                 this.limpiar();
                 this.limpiarIngreso();
              }
          }
          else{
              Utiles_MensajesDialogo.mensajeAlerta("La orden de compra no pertenece a la empresa correspondiente");
              this.limpiar();
              this.limpiarIngreso();
          }
          
      }
    } catch (Exception ex) {
      Utiles_MensajesDialogo.mensajeAlerta("Error al obtener datos de orden\n");
      Logger.getLogger(jifIngresosAlmacen.class.getName()).log(Level.SEVERE, null, ex);
      this.limpiarTrans();
    }
  }
     private void obtenerDetallesOrdenCompra() throws Exception {
        try {
            detalles = new ArrayList<DetalleOrdenTO>();
            detallesIngreso= new ArrayList<NotaIngresoTO>();
            this.detalles = GestionPedidosDelegate.getInstance().obtenerDatosDetalleOrdensumados(this.jtfOrden.getText().trim());
            this.detallesIngreso= this.convertirDetalles_Ingresos(detalles);
           
        } catch (Exception ex) {
            Logger.getLogger(jifIngresosAlmacen.class.getName()).log(Level.SEVERE, null, ex);
        }
      if(detalles.isEmpty()){
            Utiles_MensajesDialogo.mensajeAlerta("No se han encontrado detalles pendientes de ingresar");
      }
        
      else{

        System.out.println("<<"+ordento.getTipo_moneda());
        if(ordento.getTipo_moneda()==95){
            ComprobantePagoTO comp= (ComprobantePagoTO)this.intelliHintsComprobantes.getSelectedHint();
            int comprobante= comp.getId_comprobante();
            String fec= GestionPedidosDelegate.getInstance().getConsultarTipoCambioComprobante(comprobante).get(0).getTabla();
            TipoCambioDiario tip=GestionPedidosDelegate.getInstance().getTipoCambio(fec);
            BigDecimal cambio= tip.getTipoCambio();
            for(NotaIngresoTO deta:detallesIngreso){
            deta.setPrecio(deta.getPrecio().multiply(cambio));
            deta.setValor(deta.getValor().multiply(cambio));
            }
          
      }
     }

     this.bindingGroup = new BindingGroup();
     this.jTableBinding = SwingBindings.createJTableBinding(AutoBinding.UpdateStrategy.READ, this.detallesIngreso, this.jtDetalleSuministro);
     this.bindingGroup.addBindingListener(new AbstractBindingListener() {

                      @Override public void synced(Binding binding) {
                        try{
                            if(!detallesIngreso.isEmpty()){

                                int selec=jtDetalleSuministro.getSelectedRow();
                                NotaIngresoTO detaord_aux= detallesIngreso.get(jtDetalleSuministro.convertRowIndexToModel(selec));
                                if(detaord_aux.getCantidadRecibida().compareTo(detaord_aux.getCantidad())>0){
                                    detaord_aux.setCantidadRecibida(detaord_aux.getCantidad());
                                    actualizarDetallesOrdenCompra();
                                }


                            }

                    }catch(ArrayIndexOutOfBoundsException ex){
                    }
                        catch(Exception e){
                        e.printStackTrace();
                    }

                }
            });


    JTableBinding.ColumnBinding columnBinding0 = this.jTableBinding.addColumnBinding(ELProperty.create("${suministro}"));

    columnBinding0.setColumnName("Codigo");
    columnBinding0.setColumnClass(String.class);
    columnBinding0.setEditable(false);

    JTableBinding.ColumnBinding columnBinding1 = this.jTableBinding.addColumnBinding(ELProperty.create("${descripcion}"));

    columnBinding1.setColumnName("Denominacion");
    columnBinding1.setColumnClass(String.class);
    columnBinding1.setEditable(false);

    JTableBinding.ColumnBinding columnBinding2 = this.jTableBinding.addColumnBinding(ELProperty.create("${descripcionValor}"));

    columnBinding2.setColumnName("Unidad");
    columnBinding2.setColumnClass(String.class);
    columnBinding2.setEditable(false);

    JTableBinding.ColumnBinding columnBinding3 = this.jTableBinding.addColumnBinding(ELProperty.create("${cantidad}"));

    columnBinding3.setColumnName("Cantidad");
    columnBinding3.setColumnClass(String.class);
    columnBinding3.setEditable(false);

    JTableBinding.ColumnBinding columnBinding4 = this.jTableBinding.addColumnBinding(ELProperty.create("${precio}"));

    columnBinding4.setColumnName("Prec.Uni");
    columnBinding4.setColumnClass(String.class);
    columnBinding4.setEditable(false);

    JTableBinding.ColumnBinding columnBinding5 = this.jTableBinding.addColumnBinding(ELProperty.create("${valor}"));

    columnBinding5.setColumnName("Valor");
    columnBinding5.setColumnClass(String.class);
    columnBinding5.setEditable(false);

     JTableBinding.ColumnBinding columnBinding6 = this.jTableBinding.addColumnBinding(ELProperty.create("${cantidadRecibida}"));

    columnBinding6.setColumnName("cant.Recib");
    columnBinding6.setColumnClass(String.class);
    columnBinding6.setEditable(true);



    this.bindingGroup.addBinding(this.jTableBinding);
    this.bindingGroup.bind();
    int[] porcentajes= {10,40,10,10,10,10,10};

    try {
         Utiles_Tabla.definirAnchoColumnasJTable(jtDetalleSuministro, porcentajes);
          //MiTablePrint.autoSizeTableColumns(jtDetalleSuministro);
        } catch (Exception ex) {
            Logger.getLogger(jifAdministrarStock.class.getName()).log(Level.SEVERE, null, ex);
        }
    
  }
     private void actualizarDetallesOrdenCompra() {


    this.bindingGroup = new BindingGroup();
    this.jTableBinding = SwingBindings.createJTableBinding(AutoBinding.UpdateStrategy.READ, this.detallesIngreso, this.jtDetalleSuministro);
    this.bindingGroup.addBindingListener(new AbstractBindingListener() {

                      @Override public void synced(Binding binding) {
                        try{
                            if(!detallesIngreso.isEmpty()){

                                int selec=jtDetalleSuministro.getSelectedRow();
                                NotaIngresoTO detaord_aux= detallesIngreso.get(jtDetalleSuministro.convertRowIndexToModel(selec));
                                if(detaord_aux.getCantidadRecibida().compareTo(detaord_aux.getCantidad())>0){
                                    detaord_aux.setCantidadRecibida(detaord_aux.getCantidad());
                                    actualizaTablaDetalle();
                                }


                            }

                    }catch(ArrayIndexOutOfBoundsException ex){
                    }
                        catch(Exception e){
                        e.printStackTrace();
                    }

                }
            });

    JTableBinding.ColumnBinding columnBinding0 = this.jTableBinding.addColumnBinding(ELProperty.create("${suministro}"));

    columnBinding0.setColumnName("Codigo");
    columnBinding0.setColumnClass(String.class);
    columnBinding0.setEditable(false);

    JTableBinding.ColumnBinding columnBinding1 = this.jTableBinding.addColumnBinding(ELProperty.create("${descripcion}"));

    columnBinding1.setColumnName("Denominacion");
    columnBinding1.setColumnClass(String.class);
    columnBinding1.setEditable(false);

    JTableBinding.ColumnBinding columnBinding2 = this.jTableBinding.addColumnBinding(ELProperty.create("${descripcionValor}"));

    columnBinding2.setColumnName("Unidad");
    columnBinding2.setColumnClass(String.class);
    columnBinding2.setEditable(false);

    JTableBinding.ColumnBinding columnBinding3 = this.jTableBinding.addColumnBinding(ELProperty.create("${cantidad}"));

    columnBinding3.setColumnName("Cantidad");
    columnBinding3.setColumnClass(String.class);
    columnBinding3.setEditable(false);

    JTableBinding.ColumnBinding columnBinding4 = this.jTableBinding.addColumnBinding(ELProperty.create("${precio}"));

    columnBinding4.setColumnName("Prec.Uni");
    columnBinding4.setColumnClass(String.class);
    columnBinding4.setEditable(false);

    JTableBinding.ColumnBinding columnBinding5 = this.jTableBinding.addColumnBinding(ELProperty.create("${valor}"));

    columnBinding5.setColumnName("Valor");
    columnBinding5.setColumnClass(String.class);
    columnBinding5.setEditable(false);

     JTableBinding.ColumnBinding columnBinding6 = this.jTableBinding.addColumnBinding(ELProperty.create("${cantidadRecibida}"));

    columnBinding6.setColumnName("cant.Recib");
    columnBinding6.setColumnClass(String.class);
    columnBinding6.setEditable(true);



    this.bindingGroup.addBinding(this.jTableBinding);
    this.bindingGroup.bind();
    int[] porcentajes= {10,40,10,10,10,10,10};

    try {
         Utiles_Tabla.definirAnchoColumnasJTable(jtDetalleSuministro, porcentajes);
          //MiTablePrint.autoSizeTableColumns(jtDetalleSuministro);
        } catch (Exception ex) {
            Logger.getLogger(jifAdministrarStock.class.getName()).log(Level.SEVERE, null, ex);
        }

  }
    public void obtenerDetallesIngreso(){
        try {
            detallesOrden= new ArrayList<DetalleOrdenTO>();
            this.detallesOrden = GestionPedidosDelegate.getInstance().obtenerDatosDetalleOrden(this.jtfOrden.getText().trim());
            if(ordento.getTipo_moneda()==95){
            ComprobantePagoTO comp= (ComprobantePagoTO)this.intelliHintsComprobantes.getSelectedHint();
            int comprobante= comp.getId_comprobante();
            String fec= GestionPedidosDelegate.getInstance().getConsultarTipoCambioComprobante(comprobante).get(0).getTabla();
            TipoCambioDiario tip=GestionPedidosDelegate.getInstance().getTipoCambio(fec);
            BigDecimal cambio= tip.getTipoCambio();
            for(DetalleOrdenTO deta:detallesOrden){
            deta.setPrecio(deta.getPrecio().multiply(cambio));
            deta.setValor(deta.getValor().multiply(cambio));
            }
          
            }
        } catch (Exception ex) {
            Logger.getLogger(jifIngresosAlmacen.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
   
     public String registrarIngreso() throws Exception{
        BigDecimal sumatotal= BigDecimal.ZERO;
        String codigo=null;
        List detalle_ingreso = new ArrayList(1);
        Orden or= new Orden();
        or.setNroOrden(this.jtfOrden.getText());
        Parametros param= Listas.getParametrosID("SU1");
        String ano = param.getParam1();
        String mes = param.getParam2();

        Date fecha = new Date(VerificarDatos.verificaFecha(this.jtfFecha.getText()).getTime());
        Utiles_Fecha utf = new Utiles_Fecha(fecha);
        if ((!utf.getAnio().equalsIgnoreCase(ano)) || (!utf.getMes().equalsIgnoreCase(mes))) {
        Utiles_MensajesDialogo.mensajeError("La fecha debe coincidir con el mes actual: " + ano + " - " + mes);
        }
        else{
        Movimiento mov= new Movimiento();

        //agregamos comprobantes
         ComprobantePagoTO comp =new ComprobantePagoTO();
        comp= (ComprobantePagoTO)this.intelliHintsComprobantes.getSelectedHint();
        int comprobante= comp.getId_comprobante();
        BigDecimal impuesto=comp.getImpuesto().add(BigDecimal.ONE);
        System.out.println("cc"+comprobante);
        System.out.println("ii"+impuesto);
        mov.setAlmacenOrigen(comprobante);
        //-------------

        mov.setAnio(ano);
        mov.setFecha(fecha);
        mov.setMes(mes);
        mov.setNroOrden(or);
        mov.setSerie(this.jtfSerie.getText());
        mov.setNumero(this.jtfNumero.getText());
        mov.setTipoDocumento(Utiles_Convertir.convertirToTipo_TipoTO((TipoTO)this.jcbTipoDocumento.getSelectedItem()));
        mov.setTipoIngreso(Utiles_Convertir.convertirToTipo_TipoTO((TipoTO)this.jcbTipoIngreso.getSelectedItem()));
        mov.setTipoMovimiento(Utiles_Convertir.convertirToTipo_TipoTO((TipoTO)this.listaTipos.get(0)));
        mov.setIdAlmacen(Utiles_Convertir.convertirTOAlmacen_AlmacenTO((AlmacenTO)this.jcbAlmacen.getSelectedItem()));
        mov.setEmpresa(Utiles_Convertir.convertirToEmpresa_EmpresaTO((EmpresaTO)this.jcbEmpresa.getSelectedItem()));
        mov.setIdZona(Utiles_Convertir.convertirToZona_ZonaTO((ZonaTO)this.jcbZona.getSelectedItem()));
        mov.setIdSubalmacen(Utiles_Convertir.convertirTosubAlmacen_subAlmacenTO((SubAlmacenTO)this.jcbSubAlmacen.getSelectedItem()));
        mov.setObservacion(this.jtaObservacion.getText());
        boolean prod=false;
        if(this.jcbProduccion.isSelected()){
            prod=true;
        }
        mov.setIsProduccion(prod);
        BigDecimal cantidadesRecibidas[]= new BigDecimal[this.detallesIngreso.size()];
        String suministros[]= new String[this.detallesIngreso.size()];
        BigDecimal cantidadesPedida[]= new BigDecimal[this.detalles.size()];
        Double porcentajes[]= new Double[this.detalles.size()];
        int contadores[]=new int[this.detalles.size()];
        int conta[]=new int[this.detalles.size()];
        double suma[]=new double[this.detalles.size()];



        for(int i=0; i<this.detallesIngreso.size(); i++){
              cantidadesRecibidas[i]= new BigDecimal(jtDetalleSuministro.getValueAt(i, 6).toString());
              suministros[i]= jtDetalleSuministro.getValueAt(i, 0).toString();
              cantidadesPedida[i]=detalles.get(i).getCantidad();
              porcentajes[i]= Double.parseDouble(cantidadesRecibidas[i]+"")/Double.parseDouble(cantidadesPedida[i]+"");
              suma[i]=0;
        }
        for(int i=0; i<this.detallesOrden.size(); i++){
              for(int j=0; j<suministros.length; j++){
                  if(suministros[j].compareTo(detallesOrden.get(i).getSuministro())==0){
                   contadores[j]= contadores[j]+1;
                  }
              }
        }

        for (DetalleOrdenTO deta : this.detallesOrden) {
          DetalleMovimiento detall = new DetalleMovimiento(deta.getCorrelativo(), deta.getNroOrden());
          detall.setFecha(fecha);
          detall.setPrecio(deta.getPrecio());
          detall.setTipo_moneda(Utiles_Convertir.convertirToTipo_TipoTO((TipoTO)this.jcboMoneda.getSelectedItem()).getIdTablaTipo());
          detall.setCambio_moneda(BigDecimal.ONE);
          detall.setTipoMovimiento(Utiles_Convertir.convertirToTipo_TipoTO((TipoTO)this.listaTipos.get(0)));
          BigDecimal cantidad= deta.getCantidad();

          for(int i=0; i<suministros.length; i++){
             if(suministros[i].compareTo(deta.getSuministro())==0){
                 conta[i]=conta[i]+1;
                 if(conta[i]!=contadores[i]){
                      int valor=(int)(Double.parseDouble(cantidad+"")*porcentajes[i]*100);
                      double valor1=valor/100.00;
                      detall.setCantidad(new BigDecimal(valor1));
                      suma[i]=suma[i]+valor1;
                 }
                 else{
                     detall.setCantidad(new BigDecimal(Double.parseDouble(cantidadesRecibidas[i]+"")-suma[i]));
                 }
                 sumatotal=sumatotal.add(detall.getCantidad().multiply(deta.getPrecio()));
             }
          }
          detalle_ingreso.add(detall);
        }
        
        //agregamos para comprobante
        //mov.setNroDevolucion(impuesto+"");//impuesto del comprobante  de la orden escogida
        mov.setNroDevolucion(sumatotal.multiply(impuesto).divide(new BigDecimal(this.txtCambio.getText()), RoundingMode.HALF_UP)+"");
        if(sumatotal.multiply(impuesto).compareTo(new BigDecimal(this.jtfMonto.getText()).multiply(new BigDecimal(this.txtCambio.getText())).add(BigDecimal.ONE))>0){
            codigo="";
        }
        else{
            if(sumatotal.multiply(impuesto).compareTo(new BigDecimal(this.jtfMonto.getText()).multiply(new BigDecimal(this.txtCambio.getText())).subtract(BigDecimal.ONE))<0)
            mov.setAlmacenDestino(0);// tipo de atencion del comprobante de la orden escogida
            else
            mov.setAlmacenDestino(1);
            codigo=GestionPedidosDelegate.getInstance().insertarNotaIngreso(Propiedades.getUsuario(),Propiedades.getMac(),mov, detalle_ingreso,codigoTemporal,1);
        }
        }
        //-------
        return codigo;
     }
     public EmpresaTO obtenerEmpresa(String codigo){
        EmpresaTO dep= new EmpresaTO();
        for(int i=0 ; i<this.empresas.size(); i++){
            if((((EmpresaTO)empresas.get(i)).getCodigo().trim()).compareTo(codigo)==0){
                dep= (EmpresaTO)empresas.get(i);
            }
        }
        return dep;
    }
      public ZonaTO obtenerZona(String nombre){
        ZonaTO dep= new ZonaTO();
        for(int i=0 ; i<this.zonas.size(); i++){
            if((((ZonaTO)zonas.get(i)).getNom_zona().trim()).compareTo(nombre)==0){
                dep= (ZonaTO)zonas.get(i);
            }
        }
        return dep;
    }
     public AlmacenTO obtenerAlmacen(String nombre){
        AlmacenTO dep= new AlmacenTO();
        for(int i=0 ; i<this.almacenes.size(); i++){
            if(((AlmacenTO)almacenes.get(i)).getDescripcion().trim().compareTo(nombre)==0){
                dep= (AlmacenTO)almacenes.get(i);
            }
        }
        return dep;
    }
  public SubAlmacenTO obtenerSubAlmacen(String nombre){
        SubAlmacenTO dep= new SubAlmacenTO();
        for(int i=0 ; i<this.subalmacenes.size(); i++){
            if(((SubAlmacenTO)subalmacenes.get(i)).getDescripcion().compareTo(nombre)==0){
                dep= (SubAlmacenTO)subalmacenes.get(i);
            }
        }
        return dep;
    }
  private void verReporteOrden(){
        try {
            HashMap parametros = new HashMap();
            parametros.put("idMovimiento", this.jtfOrden.getText());
            JasperViewer.viewReport(GestionPedidosDelegate.getInstance().generarReporte("NotaIngreso.jasper", parametros), false);
        } catch (Exception ex) {
            Logger.getLogger(jifIngresosAlmacen.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }
  public void GenerarReporte(String codigo){
      if(codigo!=null){
        JasperViewer jv = null;
        JasperPrint jp = null;
        Map parametros = new HashMap();
        parametros.put("idMovimiento", codigo);
        try {
            jp=GestionPedidosDelegate.getInstance().generarReporteIngreso("NotaIngresoFLP.jasper", parametros);
            jv = new JasperViewer(jp, false);
            jv.setExtendedState(javax.swing.JFrame.MAXIMIZED_BOTH);
            jv.setVisible(true);
        }catch (Exception e) {
            Utiles_MensajesDialogo.mensajeError("No se pudo realizar la transaccion");
        }
      }


  }

   
    private void buscarComprobante() throws Exception
  {

        ComprobantePagoTO comp =new ComprobantePagoTO();
        comp= (ComprobantePagoTO)this.intelliHintsComprobantes.getSelectedHint();
        this.jtfMonto.setText(comp.getMonto()+"");
        int comprobante= comp.getId_comprobante();
        String fec= GestionPedidosDelegate.getInstance().getConsultarTipoCambioComprobante(comprobante).get(0).getTabla();
        TipoCambioDiario tip=GestionPedidosDelegate.getInstance().getTipoCambio(fec);
        BigDecimal cambio= tip.getTipoCambio();
        this.txtCambio.setText(cambio+"");

        this.obtenerDetallesIngreso();
        this.obtenerDetallesOrdenCompra();




  }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        cboBeanBindingTipo1 = new administracion.BeanBinding.CboBeanBindingTipo();
        cboBeanBindingAno1 = new administracion.BeanBinding.CboBeanBindingAno();
        cboBeanBindingMes1 = new administracion.BeanBinding.CboBeanBindingMes();
        cboBeanBindingZona1 = new administracion.BeanBinding.CboBeanBindingZona();
        cboBeanBindingTipo2 = new administracion.BeanBinding.CboBeanBindingTipo();
        cboBeanBindingAlmacen1 = new administracion.BeanBinding.cboBeanBindingAlmacen();
        cboBeanBindingSubAlmacen1 = new administracion.BeanBinding.CboBeanBindingSubAlmacen();
        cboBeanBindingTipo3 = new administracion.BeanBinding.CboBeanBindingTipo();
        cboBeanBindingRoles1 = new administracion.BeanBinding.cboBeanBindingRoles();
        cboBeanBindingEmpresa1 = new administracion.BeanBinding.CboBeanBindingEmpresa();
        jCheckBox2 = new javax.swing.JCheckBox();
        cboBeanBindingTipo4 = new administracion.BeanBinding.CboBeanBindingTipo();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtDetalleSuministro = new javax.swing.JTable();
        this.jtDetalleSuministro.getTableHeader().setReorderingAllowed(false) ;
        jbtAgregar = new javax.swing.JButton();
        jbEliminaDetalle = new javax.swing.JButton();
        jbtAceptar = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtaObservacion = new javax.swing.JTextArea();
        jLabel3 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        lblProveedor = new javax.swing.JLabel();
        jtfRuc = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jtfProveedor = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jcbTipoDocumento = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jtfSerie = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jtfNumero = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jcbAlmacen = new javax.swing.JComboBox();
        jLabel13 = new javax.swing.JLabel();
        jcbSubAlmacen = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        jtfOrden = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jcbEmpresa = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        jcbZona = new javax.swing.JComboBox();
        jcbTipoIngreso = new javax.swing.JComboBox();
        jLabel17 = new javax.swing.JLabel();
        jcboMoneda = new javax.swing.JComboBox();
        jlabelmoneda = new javax.swing.JLabel();
        jcbProduccion = new javax.swing.JCheckBox();
        jtfFecha = new javax.swing.JFormattedTextField(this.mascaraFechaIngreso);
        jtfFactura = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel34 = new javax.swing.JLabel();
        jtfMonto = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jblCambio = new javax.swing.JLabel();
        txtCambio = new javax.swing.JTextField();

        jCheckBox2.setText("jCheckBox2");

        setTitle("REGISTRAR INGRESOS ALMACEN");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "DETALLE INGRESO", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 0, 255))); // NOI18N

        jtDetalleSuministro.setFont(new java.awt.Font("Arial", 0, 12));
        jtDetalleSuministro.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "CODIGO", "DENOMINACION", "UNIDAD", "CANTIDAD ORDENADA", "PRECIO UNITARIO", "VALOR", "CANTIDAD RECIBIDA"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane2.setViewportView(jtDetalleSuministro);

        jbtAgregar.setFont(new java.awt.Font("Arial", 1, 12));
        jbtAgregar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/add.png"))); // NOI18N
        jbtAgregar.setMnemonic('A');
        jbtAgregar.setText("AGREGAR");
        jbtAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtAgregarActionPerformed(evt);
            }
        });

        jbEliminaDetalle.setFont(new java.awt.Font("Arial", 0, 12));
        jbEliminaDetalle.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/remove.png"))); // NOI18N
        jbEliminaDetalle.setMnemonic('E');
        jbEliminaDetalle.setText("ELIMINAR");
        jbEliminaDetalle.setToolTipText("Eliminar el detalle seleccionado");
        jbEliminaDetalle.setEnabled(false);
        jbEliminaDetalle.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jbEliminaDetalle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbEliminaDetalleActionPerformed(evt);
            }
        });
        jbEliminaDetalle.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jbEliminaDetalleKeyPressed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jbtAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbEliminaDetalle)
                .addContainerGap(419, Short.MAX_VALUE))
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 642, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbEliminaDetalle)
                    .addComponent(jbtAgregar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 247, Short.MAX_VALUE))
        );

        jbtAceptar.setFont(new java.awt.Font("Arial", 1, 12));
        jbtAceptar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/button_ok.png"))); // NOI18N
        jbtAceptar.setMnemonic('A');
        jbtAceptar.setText("ACEPTAR");
        jbtAceptar.setEnabled(false);
        jbtAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtAceptarActionPerformed(evt);
            }
        });

        jButton2.setFont(new java.awt.Font("Arial", 1, 12));
        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/button_cancel.png"))); // NOI18N
        jButton2.setMnemonic('C');
        jButton2.setText("CERRAR");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setFont(new java.awt.Font("Arial", 1, 12));
        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/view_text.png"))); // NOI18N
        jButton3.setMnemonic('V');
        jButton3.setText("VER NOTA INGRESO");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jtaObservacion.setColumns(20);
        jtaObservacion.setRows(5);
        jScrollPane1.setViewportView(jtaObservacion);

        jLabel3.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel3.setText("OBSERVACION:");

        lblProveedor.setFont(new java.awt.Font("Arial", 1, 12));
        lblProveedor.setText("RUC PROVEEDOR");

        jtfRuc.setFont(new java.awt.Font("Arial", 0, 12));
        jtfRuc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfRucActionPerformed(evt);
            }
        });

        jLabel8.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel8.setText("PROVEEDOR:");

        jtfProveedor.setFont(new java.awt.Font("Arial", 0, 12));
        jtfProveedor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfProveedorActionPerformed(evt);
            }
        });
        jtfProveedor.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jtfProveedorKeyPressed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblProveedor)
                .addGap(21, 21, 21)
                .addComponent(jtfRuc, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jtfProveedor, javax.swing.GroupLayout.PREFERRED_SIZE, 313, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(72, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblProveedor)
                    .addComponent(jLabel8)
                    .addComponent(jtfProveedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfRuc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(6, Short.MAX_VALUE))
        );

        jLabel4.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel4.setText("DOC. REFER:");

        jcbTipoDocumento.setFont(new java.awt.Font("Arial", 0, 12));

        org.jdesktop.beansbinding.ELProperty eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cboBeanBindingTipo2, eLProperty, jcbTipoDocumento);
        bindingGroup.addBinding(jComboBoxBinding);

        jcbTipoDocumento.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jcbTipoDocumentoKeyPressed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel1.setText("SERIE");

        jLabel2.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jLabel2.setText("NUMERO");

        jLabel14.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel14.setText("ALMACEN:");

        jcbAlmacen.setFont(new java.awt.Font("Arial", 0, 12));

        eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cboBeanBindingAlmacen1, eLProperty, jcbAlmacen);
        bindingGroup.addBinding(jComboBoxBinding);

        jcbAlmacen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbAlmacenActionPerformed(evt);
            }
        });
        jcbAlmacen.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jcbAlmacenKeyPressed(evt);
            }
        });

        jLabel13.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel13.setText("UBICACION:");

        jcbSubAlmacen.setFont(new java.awt.Font("Arial", 0, 12));

        eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cboBeanBindingSubAlmacen1, eLProperty, jcbSubAlmacen);
        bindingGroup.addBinding(jComboBoxBinding);

        jcbSubAlmacen.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jcbSubAlmacenKeyPressed(evt);
            }
        });

        jLabel7.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel7.setText("Nº DOCUMENTO");

        jtfOrden.setFont(new java.awt.Font("Arial", 0, 12));
        jtfOrden.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfOrdenActionPerformed(evt);
            }
        });
        jtfOrden.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jtfOrdenKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jtfOrdenKeyReleased(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel6.setText("FECHA:");

        eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cboBeanBindingEmpresa1, eLProperty, jcbEmpresa);
        bindingGroup.addBinding(jComboBoxBinding);

        jcbEmpresa.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jcbEmpresaKeyPressed(evt);
            }
        });

        jLabel9.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel9.setText("SUCURSAL");

        jcbZona.setFont(new java.awt.Font("Arial", 0, 12));

        eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cboBeanBindingZona1, eLProperty, jcbZona);
        bindingGroup.addBinding(jComboBoxBinding);

        jcbZona.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jcbZonaItemStateChanged(evt);
            }
        });
        jcbZona.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbZonaActionPerformed(evt);
            }
        });
        jcbZona.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jcbZonaKeyPressed(evt);
            }
        });

        jcbTipoIngreso.setFont(new java.awt.Font("Arial", 0, 12));

        eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cboBeanBindingTipo1, eLProperty, jcbTipoIngreso);
        bindingGroup.addBinding(jComboBoxBinding);

        jcbTipoIngreso.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jcbTipoIngresoItemStateChanged(evt);
            }
        });
        jcbTipoIngreso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbTipoIngresoActionPerformed(evt);
            }
        });
        jcbTipoIngreso.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jcbTipoIngresoKeyPressed(evt);
            }
        });

        jLabel17.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel17.setText("TIPO INGRESO");

        eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cboBeanBindingTipo4, eLProperty, jcboMoneda);
        bindingGroup.addBinding(jComboBoxBinding);

        jcboMoneda.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jcboMonedaItemStateChanged(evt);
            }
        });
        jcboMoneda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcboMonedaActionPerformed(evt);
            }
        });

        jlabelmoneda.setFont(new java.awt.Font("Arial", 1, 12));
        jlabelmoneda.setText("TIPO MONEDA");

        jcbProduccion.setFont(new java.awt.Font("Arial", 1, 12));
        jcbProduccion.setText("PRODUCCION");

        jtfFecha.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jtfFechaKeyPressed(evt);
            }
        });

        jtfFactura.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfFacturaActionPerformed(evt);
            }
        });
        jtfFactura.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jtfFacturaKeyPressed(evt);
            }
        });

        jLabel5.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel5.setText("COMPROBANTE");

        jLabel34.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel34.setText("MONTO");

        jtfMonto.setEditable(false);

        jLabel10.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel10.setText("EMPRESA");

        jblCambio.setFont(new java.awt.Font("Arial", 1, 12));
        jblCambio.setText("CAMBIO MONEDA");

        txtCambio.setEditable(false);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(9, 9, 9)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 502, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(60, 60, 60)
                        .addComponent(jbtAceptar, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel17)
                                    .addComponent(jLabel10)
                                    .addComponent(jLabel14)
                                    .addComponent(jLabel6)
                                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(13, 13, 13)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jcbEmpresa, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jcbAlmacen, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jcbTipoDocumento, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jtfFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jtfFactura, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jcbTipoIngreso, javax.swing.GroupLayout.PREFERRED_SIZE, 193, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(jLabel5))
                        .addGap(31, 31, 31)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jlabelmoneda)
                            .addComponent(jLabel13)
                            .addComponent(jLabel9)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel1)
                                    .addComponent(jLabel34))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jtfMonto, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jcboMoneda, 0, 240, Short.MAX_VALUE)
                            .addComponent(jcbSubAlmacen, 0, 240, Short.MAX_VALUE)
                            .addComponent(jcbZona, 0, 240, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jtfOrden, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jcbProduccion))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jblCambio)
                                    .addComponent(jtfSerie, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(txtCambio, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel2)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jtfNumero, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)))))))
                .addContainerGap())
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel17)
                            .addComponent(jcbTipoIngreso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jcbEmpresa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel10))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jcbAlmacen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel14))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(jtfFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jcbTipoDocumento, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(jtfFactura, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(jtfOrden, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jcbProduccion))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel9)
                            .addComponent(jcbZona, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel13)
                            .addComponent(jcbSubAlmacen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jlabelmoneda)
                            .addComponent(jcboMoneda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jtfNumero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jtfSerie, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2))
                        .addGap(14, 14, 14)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel34)
                            .addComponent(jtfMonto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jblCambio)
                            .addComponent(txtCambio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(11, 11, 11)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(2, 2, 2)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(16, 16, 16)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jbtAceptar, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jtfOrdenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfOrdenActionPerformed

           if(this.jcbEmpresa.getSelectedIndex()>-1){
                if(this.jcbTipoIngreso.getSelectedIndex()>-1){
                    Tipo t=Utiles_Convertir.convertirToTipo_TipoTO((TipoTO)this.jcbTipoIngreso.getSelectedItem());
                    if(t.getDescripcionValor().toString().compareTo("COMPRA")==0 || t.getDescripcionValor().toString().compareTo("TRANSFERENCIA")==0){
                        this.jtfOrden.setText(this.intelliHintsCodigos.getSelectedHint().toString());
                        if(this.jtfOrden.getText().length()==0){
                            this.limpiarIngreso();
                            this.limpiar();
                         }
                    }
              }
        }
         

      
    }//GEN-LAST:event_jtfOrdenActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
         int res = javax.swing.JOptionPane.showConfirmDialog( this,"Esta seguro de salir?",
                "Confirmar",javax.swing.JOptionPane.YES_NO_OPTION );
        if(res==javax.swing.JOptionPane.YES_OPTION){
            this.dispose();
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jcbTipoIngresoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jcbTipoIngresoItemStateChanged

        if(this.jcbTipoIngreso.getSelectedIndex()>=0){
            Tipo t=Utiles_Convertir.convertirToTipo_TipoTO((TipoTO)this.jcbTipoIngreso.getSelectedItem());
            if(t.getDescripcionValor().toString().compareTo("COMPRA")==0){
                if(Listas.getInventario()){
                       Utiles_MensajesDialogo.mensajeAlerta("Hay un inventario iniciado actualmente solo se pueden hacer ingresos por ajuste de Inventario");
                       this.jcbTipoIngreso.setSelectedIndex(3);
                }
                else{
                    this.jtfOrden.setVisible(true);
                    this.jLabel7.setVisible(true);
                    this.jcbZona.setEnabled(false);
                    this.jcbAlmacen.setEnabled(false);
                    this.jcbSubAlmacen.setEnabled(false);
                    this.jbtAgregar.setVisible(false);
                    this.jbEliminaDetalle.setVisible(false);
                    this.jlabelmoneda.setEnabled(false);
                    this.jcboMoneda.setEnabled(false);
                    this.jPanel2.setVisible(false);
                    this.jlabelmoneda.setVisible(true);
                    this.txtCambio.setVisible(true);
                    this.jLabel5.setVisible(true);
                    this.jtfFactura.setVisible(true);
                    this.jLabel34.setVisible(true);
                    this.jblCambio.setVisible(true);
                    this.jtfMonto.setVisible(true);
                    pack();
                    try {
                        this.obtenerCodigos();
                    } catch (Exception ex) {
                        Logger.getLogger(jifIngresosAlmacen.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
             }
            else{
               if(t.getDescripcionValor().toString().compareTo("TRANSFERENCIA")==0){
                if(Listas.getInventario()){
                       Utiles_MensajesDialogo.mensajeAlerta("Hay un inventario iniciado actualmente solo se pueden hacer ingresos por ajuste de Inventario");
                       this.jcbTipoIngreso.setSelectedIndex(3);
                }
                else{
                    this.jtfOrden.setVisible(true);
                    this.jLabel7.setVisible(true);
                    this.jcbZona.setEnabled(false);
                    this.jcbAlmacen.setEnabled(false);
                    this.jcbSubAlmacen.setEnabled(false);
                    this.jbtAgregar.setVisible(false);
                    this.jbEliminaDetalle.setVisible(false);
                    this.jPanel2.setVisible(false);
                    this.jlabelmoneda.setEnabled(false);
                    this.jcboMoneda.setEnabled(false);
                    this.jlabelmoneda.setVisible(false);
                    this.txtCambio.setVisible(false);
                    this.jLabel5.setVisible(false);
                    this.jtfFactura.setVisible(false);
                    this.jLabel34.setVisible(false);
                    this.jblCambio.setVisible(false);
                    this.jtfMonto.setVisible(false);
                    pack();
                     try {
                        this.obtenerCodigos();
                    } catch (Exception ex) {
                        Logger.getLogger(jifIngresosAlmacen.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }

            }
               else{
                   if(t.getDescripcionValor().toString().compareTo("REGULARIZAR INGRESO")==0 || t.getDescripcionValor().toString().compareTo("RECEPCION MATERIA PRIMA")==0){
                 if(Listas.getInventario()){
                  Utiles_MensajesDialogo.mensajeAlerta("Hay un inventario iniciado actualmente solo se pueden hacer ingresos por ajuste de Inventario");
                  this.jcbTipoIngreso.setSelectedIndex(3);
                }
                 else{
                    this.jtfOrden.setVisible(false);
                    this.jLabel7.setVisible(false);
                    this.jcbZona.setEnabled(true);
                    this.jcbAlmacen.setEnabled(false);
                    this.jcbSubAlmacen.setEnabled(false);
                    this.jbtAgregar.setVisible(true);
                    this.jbEliminaDetalle.setVisible(true);
                    this.jPanel2.setVisible(true);
                    this.jlabelmoneda.setEnabled(true);
                    this.jcboMoneda.setEnabled(true);
                    this.jlabelmoneda.setVisible(false);
                    this.txtCambio.setVisible(false);
                    this.jLabel5.setVisible(false);
                    this.jtfFactura.setVisible(false);
                    this.jLabel34.setVisible(false);
                    this.jtfMonto.setVisible(false);
                    this.jblCambio.setVisible(false);
                    pack();
                    try {
                        this.obtenerCodigos();
                    } catch (Exception ex) {
                        Logger.getLogger(jifIngresosAlmacen.class.getName()).log(Level.SEVERE, null, ex);
                    }
                 }
            }
            else{
            if(Listas.getInventario()){
                  Utiles_MensajesDialogo.mensajeAlerta("Hay un inventario iniciado actualmente solo se pueden hacer ingresos por ajuste de Inventario");
                  this.jcbTipoIngreso.setSelectedIndex(3);
            }
            else{
                this.jcbZona.setEnabled(true);
                this.jcbAlmacen.setEnabled(false);
                this.jcbSubAlmacen.setEnabled(false);
                this.jbtAgregar.setVisible(true);
                this.jbEliminaDetalle.setVisible(true);
                this.jPanel2.setVisible(false);
                this.jlabelmoneda.setEnabled(true);
                this.jcboMoneda.setEnabled(true);
                this.jlabelmoneda.setVisible(false);
                this.txtCambio.setVisible(false);
                this.jLabel5.setVisible(false);
                this.jtfFactura.setVisible(false);
                this.jLabel34.setVisible(false);
                this.jblCambio.setVisible(false);
                this.jtfMonto.setVisible(false);
                pack();
                try {
                    this.obtenerCodigos();
                } catch (Exception ex) {
                    Logger.getLogger(jifIngresosAlmacen.class.getName()).log(Level.SEVERE, null, ex);
                }
               }
             }
        }
       }
       }
      this.limpiar();
      this.limpiarIngreso();
    }//GEN-LAST:event_jcbTipoIngresoItemStateChanged

    private void jtfOrdenKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfOrdenKeyPressed

       
        if(KeyEvent.VK_ENTER == evt.getKeyCode() ||KeyEvent.VK_TAB == evt.getKeyCode()  ){
           if(this.jcbEmpresa.getSelectedIndex()>-1){
                if(this.jcbTipoIngreso.getSelectedIndex()>-1){
                Tipo t=Utiles_Convertir.convertirToTipo_TipoTO((TipoTO)this.jcbTipoIngreso.getSelectedItem());
                    if(t.getDescripcionValor().toString().compareTo("COMPRA")==0){
                        this.jtfOrden.setText(this.intelliHintsCodigos.getSelectedHint().toString());
                        if(this.jtfOrden.getText().compareTo("")!=0){
                            obtenerOrdenCompra();
                            this.jtfFecha.requestFocus();
                         }
                         else{
                             Utiles_MensajesDialogo.mensajeAlerta("No se ha ingresado ningun numero de orden de compra");
                              this.limpiarIngreso();
                              this.limpiar();
                         }

                    }
                   if(t.getDescripcionValor().toString().compareTo("TRANSFERENCIA")==0){
                         this.jtfOrden.setText(this.intelliHintsCodigos.getSelectedHint().toString());
                        if(this.jtfOrden.getText().compareTo("")!=0){
                            obtenerTransferencia();
                            this.jtfFecha.requestFocus();
                         }
                         else{
                             Utiles_MensajesDialogo.mensajeAlerta("No se ha ingresado ningun numero de transferencia");
                              this.limpiarIngreso();
                              this.limpiar();
                         }

                    }
           }
             else{
             Utiles_MensajesDialogo.mensajeAlerta("No se ha seleccionado ningun tipo de ingreso");
              this.limpiarIngreso();
              this.limpiar();
           }

          }
            else{
             Utiles_MensajesDialogo.mensajeAlerta("No se ha seleccionado ninguna empresa");
              this.limpiarIngreso();
              this.limpiar();
            }

          
        }
        
    }//GEN-LAST:event_jtfOrdenKeyPressed

    private void jbtAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtAceptarActionPerformed
        int res = javax.swing.JOptionPane.showConfirmDialog( this,"Esta seguro que desea registrar los suministros en el almacen?",
                "Confirmar",javax.swing.JOptionPane.YES_NO_OPTION );
        if(res==javax.swing.JOptionPane.YES_OPTION){
                    Tipo t=Utiles_Convertir.convertirToTipo_TipoTO((TipoTO)this.jcbTipoIngreso.getSelectedItem());
                   if(t.getDescripcionValor().toString().compareTo("COMPRA")==0){
                         if(this.jtfOrden.getText().compareTo("")!=0){
                            try {
                            codIngreso=null;
                            codIngreso=registrarIngreso();
                            if(codIngreso!=null){
                               if(codIngreso.compareTo("")==0){
                                   Utiles_MensajesDialogo.mensajeFracaso("El monto del comprobante elegido es mayor al monto que se desea ingresar \n Eliga otro comprobante para la orden");
                                }
                                else{
                                    this.limpiarIngreso();
                                    Utiles_MensajesDialogo.mensajeExito();
                                    this.jcbTipoIngreso.setEnabled(true);
                                    GenerarReporte(codIngreso);
                                }

                            }
                            } catch (Exception ex) {
                               
                                 Utiles_MensajesDialogo.mensajeFracaso("No se pudo registrar la nota de ingreso\n"+ ex.getMessage());
                            }
                         }
                         else{
                          Utiles_MensajesDialogo.mensajeAlerta("No se ha ingresado ningun numero de documento");
                         }
                   
                  }
                   else{
                        if(t.getDescripcionValor().toString().compareTo("TRANSFERENCIA")==0){
                        if(this.jtfOrden.getText().compareTo("")!=0){
                            try {
                            codIngreso=null;
                            codIngreso= this.RegistrarMovimientoTransferencia();
                            if(codIngreso!=null){
                                Utiles_MensajesDialogo.mensajeExito();
                                this.limpiar();
                                this.limpiarIngreso();
                                actualizaTablaDetalle();
                                GenerarReporte(codIngreso);
                                this.jcbTipoIngreso.setEnabled(true);
                             }
                            } catch (Exception ex) {
                                
                                 Utiles_MensajesDialogo.mensajeFracaso("No se pudo registrar la nota de ingreso\n "+ex.getMessage());
                            }
                            }
                         else{
                          Utiles_MensajesDialogo.mensajeAlerta("No se ha ingresado ningun numero de documento");
                         }
                        }
                        else{
                           if(t.getDescripcionValor().toString().compareTo("RECEPCION MATERIA PRIMA")==0){
                                try {
                                boolean estado=this.RegistrarMovimientoFicticio();
                                if(estado){
                                    Utiles_MensajesDialogo.mensajeExito();
                                    this.limpiar();
                                    this.limpiarIngreso();
                                    actualizaTablaDetalle();
                                    this.jcbTipoIngreso.setEnabled(true);
                                }
                                } catch (Exception ex) {
       
                                     Utiles_MensajesDialogo.mensajeFracaso("No se pudo registrar la nota de ingreso \n"+ ex.getMessage());
                                }
                           }
                           else{
                                try {
                                    codIngreso=null;
                                    codIngreso= this.RegistrarMovimientoDevolucion();
                                    if(codIngreso!=null){
                                    Utiles_MensajesDialogo.mensajeExito();
                                    this.limpiar();
                                    this.limpiarIngreso();
                                    actualizaTablaDetalle();
                                    this.jcbTipoIngreso.setEnabled(true);
                                }
                                } catch (Exception ex) {
                                   
                                     Utiles_MensajesDialogo.mensajeFracaso("No se pudo registrar la nota de ingreso \n "+ex.getMessage());
                                }
                           }
                        }
                    }
        }

    }//GEN-LAST:event_jbtAceptarActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        if(codIngreso!=null){
            GenerarReporte(codIngreso);
        }
        else{
        Utiles_MensajesDialogo.mensajeFracaso("No se ha seleccionado una nota  de ingreso");

        }
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jcbTipoIngresoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jcbTipoIngresoKeyPressed
       if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
       
            this.jcbEmpresa.requestFocus();
        }
    }//GEN-LAST:event_jcbTipoIngresoKeyPressed

    private void jcbTipoDocumentoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jcbTipoDocumentoKeyPressed
       if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jtfSerie.requestFocus();
        }
    }//GEN-LAST:event_jcbTipoDocumentoKeyPressed

    private void jbtAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtAgregarActionPerformed
    if(this.jcbTipoIngreso.getSelectedIndex()>=0){
        Tipo t=Utiles_Convertir.convertirToTipo_TipoTO((TipoTO)this.jcbTipoIngreso.getSelectedItem());
        if(t.getDescripcionValor().toString().compareTo("REGULARIZAR INGRESO")==0){
            if(this.detallesdevolucion.size()==0){
                Frame frm = JOptionPane.getFrameForComponent((JInternalFrame)this);
                JDialog dialog = new JDialog(frm, true);
                dialog.setLocationRelativeTo(frm);
                dialog.setTitle("Insertar Detalles del Ingresos");
                dialog.setDefaultCloseOperation(0);
                String empresa=((EmpresaTO)this.jcbEmpresa.getSelectedItem()).getCodigo();
                String ubicacion=((SubAlmacenTO)this.jcbSubAlmacen.getSelectedItem()).getCodSubAlmacen();
                String prove=this.jtfRuc.getText();
                jpDetalleTemporal panel = new jpDetalleTemporal(dialog, this,empresa, ubicacion, prove);
                dialog.add(panel);
                dialog.pack();
                dialog.setLocationRelativeTo(null);
                dialog.setVisible(true);
            }
            else{
                Utiles_MensajesDialogo.mensajeAlerta("No se puede ingresar mas de un suministro");
            }
        }
        else{
             Frame frm = JOptionPane.getFrameForComponent((JInternalFrame)this);
            JDialog dialog = new JDialog(frm, true);
            dialog.setLocationRelativeTo(frm);
            dialog.setTitle("Insertar Detalles del Ingresos");
            dialog.setDefaultCloseOperation(0);
            String empresa=Utiles_Convertir.convertirToEmpresa_EmpresaTO((EmpresaTO)this.jcbEmpresa.getSelectedItem()).getIdEmpresa();
            jpAgregaDetalleIngreso panel = new jpAgregaDetalleIngreso(dialog, this,empresa);
            dialog.add(panel);
            dialog.pack();
            dialog.setLocationRelativeTo(null);
            dialog.setVisible(true);
        }
        
    }
    else{
        Utiles_MensajesDialogo.mensajeAlerta("No se ha seleccionado ningun tipo de ingreso");
    }
       

    }//GEN-LAST:event_jbtAgregarActionPerformed

    private void jbEliminaDetalleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbEliminaDetalleActionPerformed
        
        try {
            if (this.jtDetalleSuministro.getSelectedRow() < 0) {
                Utiles_MensajesDialogo.mensajeError("Debe elegir un detalle");
                return;
            }
            if (Utiles_MensajesDialogo.mensajeConfirmacion("Esta seguro de eliminar el detalle?"))
                eliminarFila();
        } catch (Exception e) {
            e.printStackTrace();
        }
}//GEN-LAST:event_jbEliminaDetalleActionPerformed

    private void jbEliminaDetalleKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jbEliminaDetalleKeyPressed
       
        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jbEliminaDetalle.doClick();
        }
}//GEN-LAST:event_jbEliminaDetalleKeyPressed

    private void jcbTipoIngresoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbTipoIngresoActionPerformed

    }//GEN-LAST:event_jcbTipoIngresoActionPerformed

    private void jcbZonaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbZonaActionPerformed
       if(this.jcbZona.getSelectedIndex()>=0){
           llenarComboAlmacenZona();
           this.jcbAlmacen.setEnabled(true);
           this.jcbSubAlmacen.setEnabled(true);
       }
    }//GEN-LAST:event_jcbZonaActionPerformed

    private void jcbAlmacenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbAlmacenActionPerformed
       if(this.jcbAlmacen.getSelectedIndex()>=0){
           this.llenarComboUbicacionAlmacen();
       }
    }//GEN-LAST:event_jcbAlmacenActionPerformed

    private void jcbZonaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jcbZonaKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jtfOrden.requestFocus();
        }
    }//GEN-LAST:event_jcbZonaKeyPressed

    private void jcbAlmacenKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jcbAlmacenKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jcbSubAlmacen.requestFocus();
        }
    }//GEN-LAST:event_jcbAlmacenKeyPressed

    private void jcbSubAlmacenKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jcbSubAlmacenKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jtfFecha.requestFocus();
        }
    }//GEN-LAST:event_jcbSubAlmacenKeyPressed

    private void jcbEmpresaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jcbEmpresaKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            if(this.jcbEmpresa.getSelectedIndex()>=0){
                this.jcbZona.requestFocus();
            }
        }
    }//GEN-LAST:event_jcbEmpresaKeyPressed

    private void jtfOrdenKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfOrdenKeyReleased
        if(this.jcbTipoIngreso.getSelectedIndex()>=0){
         Tipo t=Utiles_Convertir.convertirToTipo_TipoTO((TipoTO)this.jcbTipoIngreso.getSelectedItem());
            try {
                this.obtenerCodigos();
            } catch (Exception ex) {
                Logger.getLogger(jifIngresosAlmacen.class.getName()).log(Level.SEVERE, null, ex);
            }
       }
    }//GEN-LAST:event_jtfOrdenKeyReleased

    private void jcbZonaItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jcbZonaItemStateChanged
    
    }//GEN-LAST:event_jcbZonaItemStateChanged

    private void jtfRucActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfRucActionPerformed
        if (this.jtfRuc.getText().trim().length() < 1)
            this.jtfProveedor.requestFocus();
        else{
            buscarRazonSocial();
        }

    }//GEN-LAST:event_jtfRucActionPerformed

    private void jtfProveedorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfProveedorActionPerformed
        buscarRazonSocial();
}//GEN-LAST:event_jtfProveedorActionPerformed

    private void jtfProveedorKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfProveedorKeyPressed
        if (this.jtfRuc.getText().trim().length() > 0)
            this.jtfRuc.setText("");
}//GEN-LAST:event_jtfProveedorKeyPressed

    private void jcboMonedaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcboMonedaActionPerformed
       
    }//GEN-LAST:event_jcboMonedaActionPerformed

    private void jcboMonedaItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jcboMonedaItemStateChanged
      
    }//GEN-LAST:event_jcboMonedaItemStateChanged

    private void jtfFechaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfFechaKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jbtAceptar.requestFocus();
        }
}//GEN-LAST:event_jtfFechaKeyPressed

    private void jtfFacturaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfFacturaActionPerformed
        this.jtfMonto.setText("");
        this.txtCambio.setText("");
        try {
            this.buscarComprobante();
        } catch (Exception ex) {
            Logger.getLogger(jifIngresosAlmacen.class.getName()).log(Level.SEVERE, null, ex);
        }
}//GEN-LAST:event_jtfFacturaActionPerformed

    private void jtfFacturaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfFacturaKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jtfMonto.setText("");
            this.txtCambio.setText("");
            try {
                this.buscarComprobante();
            } catch (Exception ex) {
                Logger.getLogger(jifIngresosAlmacen.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_jtfFacturaKeyPressed

 private void limpiar(){
        this.detallesdevolucion.clear();
        this.pack();
        
    }
    public void limpiarIngreso(){
        this.jtfSerie.setText("");
        this.jtfNumero.setText("");
        this.jtfOrden.setText("");
        this.jcbTipoDocumento.setSelectedIndex(-1);
        this.jcbEmpresa.setSelectedIndex(0);
        this.jcbZona.setSelectedIndex(-1);
        this.jcbAlmacen.setSelectedIndex(-1);
        this.jcbSubAlmacen.setSelectedIndex(-1);
        this.jtaObservacion.setText("");
        if(!detalles.isEmpty())
        this.detalles.clear();
        if(!this.detallesIngreso.isEmpty())
        this.detallesIngreso.clear();
        if(!this.detallesOrden.isEmpty())
        this.detallesOrden.clear();
        if(!this.detallesdevolucion.isEmpty())
        this.detallesdevolucion.clear();
        if(!this.detallestransferencia.isEmpty())
        this.detallestransferencia.clear();
        ordento= new OrdenTO();
        this.jtfRuc.setText("");
        this.jtfProveedor.setText("");
        codigoTemporal=-1;
        this.actualizaTablaDetalle();
        this.txtCambio.setText("");
        this.jtfMonto.setText("");
        this.jtfFactura.setText("");
    }
   
    private void cargaHintsIndependientes() {
        this.intelliHintsCodigos = new ListDataIntelliHints(this.jtfOrden, this.listacodigo);
        this.intelliHintsProveedor = new ListDataIntelliHints(this.jtfProveedor, Listas.getProveedores());
  }
  
 
   void agregaDetalleSuministro(TblBeanBindingDetalleIngreso detalle) throws Exception {
    try {

      if (verificaNoExisteSuministro(detalle)) {
        this.detallesdevolucion.add(detalle);
        actualizaTablaDetalle();
        this.jbEliminaDetalle.setEnabled(true);
      } else {
        throw new Exception("El suministro " + detalle.getNomsuministro().trim() + "\nya fue ingresado");
      }
    } catch (Exception e) {
      throw e;
    }
  }
    private boolean verificaNoExisteSuministro(TblBeanBindingDetalleIngreso detalle) {
    boolean retorno = true;
    for (TblBeanBindingDetalleIngreso det : this.detallesdevolucion) {
      if (det.getIdsuministro().equalsIgnoreCase(detalle.getIdsuministro())) {
        retorno = false;
        break;
      }
    }
    return retorno;
  }
    private void eliminarFila() {
        String id_sumi = this.jtDetalleSuministro.getValueAt(this.jtDetalleSuministro.getSelectedRow(), 0).toString().trim();

        for (TblBeanBindingDetalleIngreso det : this.detallesdevolucion) {
          if (det.getIdsuministro().equalsIgnoreCase(id_sumi)) {
            this.detallesdevolucion.remove(det);
            codigoTemporal=-1;
            break;
          }
        }
        actualizaTablaDetalle();
      }
    private void actualizaTablaDetalle() {
        this.bindingGroup = new BindingGroup();
        this.jTableBinding = SwingBindings.createJTableBinding(AutoBinding.UpdateStrategy.READ, this.detallesdevolucion, this.jtDetalleSuministro);
        this.bindingGroup.addBindingListener(new AbstractBindingListener() {

                      @Override public void synced(Binding binding) {
                        try{
                            if(!detallesdevolucion.isEmpty()){

                                int selec=jtDetalleSuministro.getSelectedRow();
                                TblBeanBindingDetalleIngreso detaord_aux= detallesdevolucion.get(jtDetalleSuministro.convertRowIndexToModel(selec));
                                detaord_aux.setValor(detaord_aux.getCantidad().multiply(detaord_aux.getPrecio()));
                                actualizaTablaDetalle();

                            }

                    }catch(ArrayIndexOutOfBoundsException ex){
                    }
                        catch(Exception e){
                        e.printStackTrace();
                    }

                }
            });
        JTableBinding.ColumnBinding columnBinding0 = this.jTableBinding.addColumnBinding(ELProperty.create("${idsuministro}"));

        columnBinding0.setColumnName("ID Suministro");
        columnBinding0.setColumnClass(String.class);
        columnBinding0.setEditable(false);

        JTableBinding.ColumnBinding columnBinding1 = this.jTableBinding.addColumnBinding(ELProperty.create("${nomsuministro}"));

        columnBinding1.setColumnName("Suministro");
        columnBinding1.setColumnClass(String.class);
        columnBinding1.setEditable(false);

        JTableBinding.ColumnBinding columnBinding2 = this.jTableBinding.addColumnBinding(ELProperty.create("${cantidad}"));

        columnBinding2.setColumnName("Cantidad");
        columnBinding2.setColumnClass(BigDecimal.class);
        columnBinding2.setEditable(false);

        JTableBinding.ColumnBinding columnBinding3 = this.jTableBinding.addColumnBinding(ELProperty.create("${precio}"));

        columnBinding3.setColumnName("Precio");
        columnBinding3.setColumnClass(BigDecimal.class);
        columnBinding3.setEditable(true);

        JTableBinding.ColumnBinding columnBinding4 = this.jTableBinding.addColumnBinding(ELProperty.create("${valor}"));

        columnBinding4.setColumnName("Valor");
        columnBinding4.setColumnClass(BigDecimal.class);
        columnBinding4.setEditable(false);
        
   
        this.bindingGroup.addBinding(this.jTableBinding);
        this.bindingGroup.bind();
        int[] porcentajes= {15,40,15,15,15};
         try {
           Utiles_Tabla.definirAnchoColumnasJTable(jtDetalleSuministro, porcentajes);
          // MiTablePrint.autoSizeTableColumns(jtDetalleSuministro);
        } catch (Exception ex) {
            Logger.getLogger(jifAdministrarStock.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        if (this.detallesdevolucion.size() > 0) {
          this.jbtAceptar.setEnabled(true);
          this.jbEliminaDetalle.setEnabled(true);
          this.jbtAceptar.requestFocus();
        } else {
          this.jbtAceptar.setEnabled(false);
          this.jbEliminaDetalle.setEnabled(false);
        }
      }

    public String RegistrarMovimientoDevolucion() throws Exception{
        boolean tienetipo=false;
        String codigo=null;
        List detalle_ingresoDev = new ArrayList(1);
        Parametros param = Listas.getParametrosID("SU1");
        String ano = param.getParam1();
        String mes = param.getParam2();

        Date fecha = new Date(VerificarDatos.verificaFecha(this.jtfFecha.getText()).getTime());
        Utiles_Fecha utf = new Utiles_Fecha(fecha);
        if ((!utf.getAnio().equalsIgnoreCase(ano)) || (!utf.getMes().equalsIgnoreCase(mes))) {
        Utiles_MensajesDialogo.mensajeError("La fecha debe coincidir con el mes actual: " + ano + " - " + mes);
        }
        else{
        Movimiento mov= new Movimiento();
        mov.setAnio(ano);
        mov.setFecha(fecha);
        mov.setMes(mes);
        mov.setSerie(this.jtfSerie.getText());
        mov.setNumero(this.jtfNumero.getText());
        if(((TipoTO)this.jcbTipoIngreso.getSelectedItem()).getDescripcion_valor().compareTo("REGULARIZAR INGRESO")==0){
             mov.setProveedor(this.jtfRuc.getText());
        }
        mov.setTipoDocumento(Utiles_Convertir.convertirToTipo_TipoTO((TipoTO)this.jcbTipoDocumento.getSelectedItem()));
        mov.setTipoIngreso(Utiles_Convertir.convertirToTipo_TipoTO((TipoTO)this.jcbTipoIngreso.getSelectedItem()));
        mov.setTipoMovimiento(Utiles_Convertir.convertirToTipo_TipoTO((TipoTO)this.listaTipos.get(0)));
        mov.setIdAlmacen(Utiles_Convertir.convertirTOAlmacen_AlmacenTO((AlmacenTO)this.jcbAlmacen.getSelectedItem()));
        mov.setIdZona(Utiles_Convertir.convertirToZona_ZonaTO((ZonaTO)this.jcbZona.getSelectedItem()));
        mov.setIdSubalmacen(Utiles_Convertir.convertirTosubAlmacen_subAlmacenTO((SubAlmacenTO)this.jcbSubAlmacen.getSelectedItem()));
        mov.setEmpresa(Utiles_Convertir.convertirToEmpresa_EmpresaTO((EmpresaTO)this.jcbEmpresa.getSelectedItem()));
        mov.setObservacion(this.jtaObservacion.getText());
        boolean prod=false;
        if(this.jcbProduccion.isSelected()){
            prod=true;
        }
        mov.setIsProduccion(prod);
        int correlativo=1;
        String centro_costos=null;
        String unidad_organica=null;
        String cod_presupuestal=null;
        String cod_proyecto=null;
        String cod_inversion=null;
        String ctacble=null;

        for (TblBeanBindingDetalleIngreso deta : this.detallesdevolucion) {

          DetalleMovimiento detall = new DetalleMovimiento();
          DetalleMovimientoPK detallepk= new DetalleMovimientoPK(correlativo, "");
          detall.setTipo_moneda(Utiles_Convertir.convertirToTipo_TipoTO((TipoTO)this.jcboMoneda.getSelectedItem()).getIdTablaTipo());

          if(this.jcboMoneda.getSelectedIndex()==1){
              TipoCambioDiario tipcambio=GestionPedidosDelegate.getInstance().getTipoCambio(this.jtfFecha.getText());
              if(tipcambio!=null){
                tienetipo=true;
                detall.setCambio_moneda(tipcambio.getTipoCambio());
              }
          }
          else{
               tienetipo=true;
               detall.setCambio_moneda(BigDecimal.ONE);
          }
          detall.setDetalleMovimientoPK(detallepk);
          detall.setCantidad(deta.getCantidad());
          detall.setCcosto(centro_costos);
          detall.setCodInv(cod_inversion);
          detall.setCodPresupuestal(cod_presupuestal);
          detall.setFecha(fecha);
          detall.setIdProyecto(cod_proyecto);
          detall.setIdSuministro(new Suministros(deta.getIdsuministro()));
          detall.setId_unidad_organica(unidad_organica);
          detall.setPrecio(deta.getPrecio().multiply(detall.getCambio_moneda()));
          detall.setTipoMovimiento(Utiles_Convertir.convertirToTipo_TipoTO((TipoTO)this.listaTipos.get(0)));
          detall.setValor(detall.getCantidad().multiply(detall.getPrecio()));
          detall.setIdZona(Utiles_Convertir.convertirToZona_ZonaTO((ZonaTO)this.jcbZona.getSelectedItem()));
          detall.setEstado_ubicacion(new Integer(0));
          correlativo++;
          detalle_ingresoDev.add(detall);
          }
         if(tienetipo){
             codigo=GestionPedidosDelegate.getInstance().insertarNotaIngreso(Propiedades.getUsuario(),Propiedades.getMac(),mov, detalle_ingresoDev,codigoTemporal,2);
             codigoTemporal=-1;
         }
         else{
            Utiles_MensajesDialogo.mensajeError("No se ha asignado un tipo de cambio en el dia");
         }
         
        }
         return codigo;
        }
      public boolean RegistrarMovimientoFicticio() throws Exception{
         boolean estado;
        List<DetalleMovimientoTemporal> detalle_ingresoDev = new ArrayList<DetalleMovimientoTemporal>();
        Parametros param = Listas.getParametrosID("SU1");
        String ano = param.getParam1();
        String mes = param.getParam2();

        Date fecha = new Date(VerificarDatos.verificaFecha(this.jtfFecha.getText()).getTime());
        Utiles_Fecha utf = new Utiles_Fecha(fecha);



        for (TblBeanBindingDetalleIngreso deta : this.detallesdevolucion) {

          DetalleMovimientoTemporal detall = new DetalleMovimientoTemporal();
           detall.setAnio(ano);
           detall.setFecha(fecha);
           detall.setMes(mes);
           detall.setSerie(this.jtfSerie.getText());
           detall.setNumero(this.jtfNumero.getText());
           detall.setRuc(this.jtfRuc.getText());
           detall.setAlmacen(Utiles_Convertir.convertirTOAlmacen_AlmacenTO((AlmacenTO)this.jcbAlmacen.getSelectedItem()).getIdAlmacen());
           detall.setZona(Utiles_Convertir.convertirToZona_ZonaTO((ZonaTO)this.jcbZona.getSelectedItem()).getIdZona());
           detall.setSubalmacen(Utiles_Convertir.convertirTosubAlmacen_subAlmacenTO((SubAlmacenTO)this.jcbSubAlmacen.getSelectedItem()).getIdSubAlmacen());
           detall.setEmpresa(Utiles_Convertir.convertirToEmpresa_EmpresaTO((EmpresaTO)this.jcbEmpresa.getSelectedItem()).getIdEmpresa());
           detall.setCantidad(deta.getCantidad());
           detall.setIdSuministro(deta.getIdsuministro());
           detall.setPrecio(deta.getPrecio());
           detall.setUsuario(Propiedades.getUsuario());
           detall.setMac(Propiedades.getMac());
            detalle_ingresoDev.add(detall);
          }

         estado=GestionPedidosDelegate.getInstance().insertarNotaIngresoFicticio(detalle_ingresoDev);
        return estado;
     }
    public String RegistrarMovimientoTransferencia() throws Exception{
        String codigo=null;
        List detalle_ingresoTra = new ArrayList(1);
        Parametros param = Listas.getParametrosID("SU1");
        String ano = param.getParam1();
        String mes = param.getParam2();

        Date fecha = new Date(VerificarDatos.verificaFecha(this.jtfFecha.getText()).getTime());
        Utiles_Fecha utf = new Utiles_Fecha(fecha);
        if ((!utf.getAnio().equalsIgnoreCase(ano)) || (!utf.getMes().equalsIgnoreCase(mes))) {
        Utiles_MensajesDialogo.mensajeError("La fecha debe coincidir con el mes actual: " + ano + " - " + mes);
        }
        else{
        Movimiento mov= new Movimiento();
        mov.setAnio(ano);
        mov.setFecha(fecha);
        mov.setMes(mes);
        mov.setIdTransferencia(new Transferencia(transferencia.getCodigo()));
        mov.setEmpresa(Utiles_Convertir.convertirToEmpresa_EmpresaTO((EmpresaTO)this.jcbEmpresa.getSelectedItem()));
        mov.setTipoIngreso(Utiles_Convertir.convertirToTipo_TipoTO((TipoTO)this.jcbTipoIngreso.getSelectedItem()));
        mov.setTipoMovimiento(Utiles_Convertir.convertirToTipo_TipoTO((TipoTO)this.listaTipos.get(0)));
        mov.setIdAlmacen(Utiles_Convertir.convertirTOAlmacen_AlmacenTO((AlmacenTO)this.jcbAlmacen.getSelectedItem()));
        mov.setIdZona(Utiles_Convertir.convertirToZona_ZonaTO((ZonaTO)this.jcbZona.getSelectedItem()));
        mov.setIdSubalmacen(Utiles_Convertir.convertirTosubAlmacen_subAlmacenTO((SubAlmacenTO)this.jcbSubAlmacen.getSelectedItem()));

        mov.setObservacion(this.jtaObservacion.getText());
        mov.setNumero(this.jtfNumero.getText());
        mov.setSerie(this.jtfSerie.getText());
        boolean prod=false;
        if(this.jcbProduccion.isSelected()){
            prod=true;
        }
        mov.setIsProduccion(prod);
        int correlativo=1;


        for (DetalleTransferenciaTO deta : this.detallestransferencia) {

          DetalleMovimiento detall = new DetalleMovimiento();
          DetalleMovimientoPK detallepk= new DetalleMovimientoPK(correlativo, "");
          detall.setDetalleMovimientoPK(detallepk);
          detall.setCantidad(deta.getCantidad());
          detall.setCcosto(deta.getCentroCostos());
          detall.setCodInv(deta.getCodInversion());
          detall.setCodPresupuestal(deta.getCodPresupuesta());
          detall.setFecha(fecha);
          detall.setIdSuministro(new Suministros(deta.getSuministro()));
          detall.setId_unidad_organica(deta.getUnidad_organica());
          detall.setPrecio(deta.getPrecio());
          detall.setTipoMovimiento(Utiles_Convertir.convertirToTipo_TipoTO((TipoTO)this.listaTipos.get(0)));
          detall.setValor(deta.getValor());
          detall.setIdZona(Utiles_Convertir.convertirToZona_ZonaTO((ZonaTO)this.jcbZona.getSelectedItem()));
          detall.setEstado_ubicacion(new Integer(0));
          detall.setTipo_moneda(Utiles_Convertir.convertirToTipo_TipoTO((TipoTO)this.jcboMoneda.getSelectedItem()).getIdTablaTipo());
          detall.setCambio_moneda(BigDecimal.ONE);
          correlativo++;
          detalle_ingresoTra.add(detall);
          }

          codigo=GestionPedidosDelegate.getInstance().insertarNotaIngreso(Propiedades.getUsuario(),Propiedades.getMac(),mov, detalle_ingresoTra,codigoTemporal,3);

        }
         return codigo;
        }

     private void llenarComboAlmacenZona() {
           try {
                  if (this.jcbZona.getSelectedItem() != null) {
                    ZonaTO selected = (ZonaTO)this.jcbZona.getSelectedItem();
                    List listaAlmacen = null;
                    List listaAlmacen_cbo = this.cboBeanBindingAlmacen1.getLista();
                    listaAlmacen_cbo.clear();
                    listaAlmacen = Listas.getAlmacenEnZona(selected);
                    this.cboBeanBindingAlmacen1.setLista(listaAlmacen);
                    this.bindingGroup.bind();
                    this.jcbAlmacen.updateUI();
                    this.jcbAlmacen.setSelectedIndex(0);
                  }
          }
            catch (Exception e) {
              Utiles_MensajesDialogo.mensajeAlerta("Error al obtener almacenes\n" + e.getMessage());
              e.printStackTrace();
              Logger.getLogger(jifIngresosAlmacen.class.getName()).log(Level.SEVERE, null, e);
            }
     }

     private void llenarComboUbicacionAlmacen() {
       try {
                  if (this.jcbAlmacen.getSelectedItem() != null) {
                    AlmacenTO selected = (AlmacenTO)this.jcbAlmacen.getSelectedItem();
                    List listaSubAlmacen = null;
                    List listaSubAlmacen_cbo = this.cboBeanBindingSubAlmacen1.getLista();
                    listaSubAlmacen_cbo.clear();
                    listaSubAlmacen = Listas.getSubAlmacenEnAlmacen(selected);
                    this.cboBeanBindingSubAlmacen1.setLista(listaSubAlmacen);
                    this.bindingGroup.bind();
                    this.jcbSubAlmacen.updateUI();
                    this.jcbSubAlmacen.setSelectedIndex(0);
                  }
          }
            catch (Exception e) {
              Utiles_MensajesDialogo.mensajeAlerta("Error al obtener Sub Almacenes\n" + e.getMessage());
              e.printStackTrace();
              Logger.getLogger(jifSalidasAlmacen.class.getName()).log(Level.SEVERE, null, e);
            }
     }
     //PARA TRANSFERENCIAS
     public void obtenerTransferencia(){
         try
        {
          transferencia= new TransferenciaTO();
          transferencia = GestionPedidosDelegate.getInstance().getDatosTransferencia(this.jtfOrden.getText().trim(),2); 
          if(transferencia.getEmpresa()!=null){
              boolean estado=false;
              String  emp=empresas.get(this.jcbEmpresa.getSelectedIndex()).getCodigo();
                  if(transferencia.getEmpresa().compareTo(emp)==0){
                    estado=true;
                  }       
              if(estado){
                  estado=false;
                  for(int i=0; i<zonas.size(); i++){
                      if(zonas.get(i).getNom_zona().compareTo(transferencia.getZona())==0){
                          estado=true;
                      }
                  }
                  if(estado){
                      this.jcbEmpresa.setSelectedItem(this.obtenerEmpresa(transferencia.getEmpresa()));
                      this.jcbZona.setSelectedItem(this.obtenerZona(transferencia.getZona()));
                      this.jcbAlmacen.setSelectedItem(this.obtenerAlmacen(transferencia.getAlmacen()));
                      this.jcbSubAlmacen.setSelectedItem(this.obtenerSubAlmacen(transferencia.getSubalmacen()));
                      this.jcbEmpresa.setEnabled(false);
                      this.jcbZona.setEnabled(false);
                      obtenerDetallesTransferencia();
                      this.jbtAceptar.setEnabled(true);
                     // this.jcbTipoIngreso.setEnabled(false);
                  }
                  else{
                      Utiles_MensajesDialogo.mensajeAlerta("La nota de transferencia no pertenece \n a las zonas asignadas al usuario");
                  }
              }
              else{
                   Utiles_MensajesDialogo.mensajeAlerta("La nota de transferencia no pertenece \n a las empresas asignadas al usuario");
              }
              
             
          }
          else{
          Utiles_MensajesDialogo.mensajeAlerta("No se ha encontrado la transferencia o ya esta regitrado el ingreso");
          }
        } catch (Exception ex) {
           
            Utiles_MensajesDialogo.mensajeAlerta("No se ha encontrado la transferencia o ya esta regitrado el ingreso");
            limpiarTrans();
          Logger.getLogger(jifIngresosAlmacen.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
      public List<NotaIngresoTO> convertirDetalles_SalidaTr( List<DetalleTransferenciaTO> listadetalles){
          List<NotaIngresoTO> deSalida= new ArrayList<NotaIngresoTO>();
          for(DetalleTransferenciaTO deta: listadetalles){
                 NotaIngresoTO ing= new NotaIngresoTO(deta.getTransferencia(),deta.getSuministro(), deta.getDescsuministro(), deta.getUnidad(),deta.getCantidad(), deta.getPrecio(), deta.getCantidad().multiply(deta.getPrecio()).setScale(5), deta.getCantidad());
                 deSalida.add(ing);
             }
          return deSalida;
      }
      private void obtenerDetallesTransferencia() {
        try {
         detallesIngreso = new ArrayList<NotaIngresoTO>();
         detallestransferencia = new ArrayList<DetalleTransferenciaTO>();
         this.detallestransferencia = GestionPedidosDelegate.getInstance().getDatosDetalleTransferencia(this.jtfOrden.getText());
         this.detallesIngreso= this.convertirDetalles_SalidaTr(detallestransferencia);
        } catch (Exception ex) {
            Logger.getLogger(jifSalidasAlmacen.class.getName()).log(Level.SEVERE, null, ex);
        }
      if(detallestransferencia.isEmpty()){
           Utiles_MensajesDialogo.mensajeAlerta("No se han encontrado detalles pendientes de entregar");
      }

    this.bindingGroup = new BindingGroup();
    this.jTableBinding = SwingBindings.createJTableBinding(AutoBinding.UpdateStrategy.READ, this.detallesIngreso, this.jtDetalleSuministro);

    JTableBinding.ColumnBinding columnBinding0 = this.jTableBinding.addColumnBinding(ELProperty.create("${suministro}"));

    columnBinding0.setColumnName("Codigo");
    columnBinding0.setColumnClass(String.class);
    columnBinding0.setEditable(false);

    JTableBinding.ColumnBinding columnBinding1 = this.jTableBinding.addColumnBinding(ELProperty.create("${descripcion}"));

    columnBinding1.setColumnName("Descripcion");
    columnBinding1.setColumnClass(String.class);
    columnBinding1.setEditable(false);

    JTableBinding.ColumnBinding columnBinding2 = this.jTableBinding.addColumnBinding(ELProperty.create("${descripcionValor}"));

    columnBinding2.setColumnName("Unidad");
    columnBinding2.setColumnClass(String.class);
    columnBinding2.setEditable(false);

    JTableBinding.ColumnBinding columnBinding3 = this.jTableBinding.addColumnBinding(ELProperty.create("${cantidad}"));

    columnBinding3.setColumnName("Cantidad");
    columnBinding3.setColumnClass(String.class);
    columnBinding3.setEditable(false);

    JTableBinding.ColumnBinding columnBinding4 = this.jTableBinding.addColumnBinding(ELProperty.create("${precio}"));

    columnBinding4.setColumnName("Prec.Uni");
    columnBinding4.setColumnClass(String.class);
    columnBinding4.setEditable(false);

    JTableBinding.ColumnBinding columnBinding5 = this.jTableBinding.addColumnBinding(ELProperty.create("${valor}"));

    columnBinding5.setColumnName("Valor");
    columnBinding5.setColumnClass(String.class);
    columnBinding5.setEditable(false);

     JTableBinding.ColumnBinding columnBinding6 = this.jTableBinding.addColumnBinding(ELProperty.create("${cantidadRecibida}"));

    columnBinding6.setColumnName("cant.Recib");
    columnBinding6.setColumnClass(String.class);
    columnBinding6.setEditable(false);



    this.bindingGroup.addBinding(this.jTableBinding);
    this.bindingGroup.bind();
      int[] porcentajes= {10,40,10,10,10,10,10};
     try {
           Utiles_Tabla.definirAnchoColumnasJTable(jtDetalleSuministro, porcentajes);
          // MiTablePrint.autoSizeTableColumns(jtDetalleSuministro);
        } catch (Exception ex) {
            Logger.getLogger(jifAdministrarStock.class.getName()).log(Level.SEVERE, null, ex);
        }

  }
   private void actualizarDetallesTransferencia() {

    this.bindingGroup = new BindingGroup();
    this.jTableBinding = SwingBindings.createJTableBinding(AutoBinding.UpdateStrategy.READ, this.detallestransferencia, this.jtDetalleSuministro);


     JTableBinding.ColumnBinding columnBinding0 = this.jTableBinding.addColumnBinding(ELProperty.create("${suministro}"));

    columnBinding0.setColumnName("Codigo");
    columnBinding0.setColumnClass(String.class);
    columnBinding0.setEditable(false);

    JTableBinding.ColumnBinding columnBinding1 = this.jTableBinding.addColumnBinding(ELProperty.create("${descsuministro}"));

    columnBinding1.setColumnName("Descripcion");
    columnBinding1.setColumnClass(String.class);
    columnBinding1.setEditable(false);

    JTableBinding.ColumnBinding columnBinding2 = this.jTableBinding.addColumnBinding(ELProperty.create("${unidad}"));

    columnBinding2.setColumnName("Unidad");
    columnBinding2.setColumnClass(String.class);
    columnBinding2.setEditable(false);

    JTableBinding.ColumnBinding columnBinding3 = this.jTableBinding.addColumnBinding(ELProperty.create("${cantidad}"));

    columnBinding3.setColumnName("Cantidad");
    columnBinding3.setColumnClass(String.class);
    columnBinding3.setEditable(false);

    JTableBinding.ColumnBinding columnBinding4 = this.jTableBinding.addColumnBinding(ELProperty.create("${precio}"));

    columnBinding4.setColumnName("Prec.Uni");
    columnBinding4.setColumnClass(String.class);
    columnBinding4.setEditable(false);

    JTableBinding.ColumnBinding columnBinding5 = this.jTableBinding.addColumnBinding(ELProperty.create("${valor}"));

    columnBinding5.setColumnName("Valor");
    columnBinding5.setColumnClass(String.class);
    columnBinding5.setEditable(false);

     JTableBinding.ColumnBinding columnBinding6 = this.jTableBinding.addColumnBinding(ELProperty.create("${cantidad}"));

    columnBinding6.setColumnName("cant.Recib");
    columnBinding6.setColumnClass(String.class);
    columnBinding6.setEditable(false);

    this.bindingGroup.addBinding(this.jTableBinding);
    this.bindingGroup.bind();
      int[] porcentajes= {10,40,10,10,10,10,10};
     try {
            Utiles_Tabla.definirAnchoColumnasJTable(jtDetalleSuministro, porcentajes);
            //MiTablePrint.autoSizeTableColumns(jtDetalleSuministro);
        } catch (Exception ex) {
            Logger.getLogger(jifAdministrarStock.class.getName()).log(Level.SEVERE, null, ex);
        }
  }

    public void limpiarTrans(){
        if(!detallestransferencia.isEmpty())
        this.detallestransferencia.clear();
        this.jcbAlmacen.setSelectedIndex(-1);
        this.jcbSubAlmacen.setSelectedIndex(-1);
        this.jtfOrden.setText("");
        this.jtaObservacion.setText("");
        this.actualizarDetallesTransferencia();
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private administracion.BeanBinding.cboBeanBindingAlmacen cboBeanBindingAlmacen1;
    private administracion.BeanBinding.CboBeanBindingAno cboBeanBindingAno1;
    private administracion.BeanBinding.CboBeanBindingEmpresa cboBeanBindingEmpresa1;
    private administracion.BeanBinding.CboBeanBindingMes cboBeanBindingMes1;
    private administracion.BeanBinding.cboBeanBindingRoles cboBeanBindingRoles1;
    private administracion.BeanBinding.CboBeanBindingSubAlmacen cboBeanBindingSubAlmacen1;
    private administracion.BeanBinding.CboBeanBindingTipo cboBeanBindingTipo1;
    private administracion.BeanBinding.CboBeanBindingTipo cboBeanBindingTipo2;
    private administracion.BeanBinding.CboBeanBindingTipo cboBeanBindingTipo3;
    private administracion.BeanBinding.CboBeanBindingTipo cboBeanBindingTipo4;
    private administracion.BeanBinding.CboBeanBindingZona cboBeanBindingZona1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JCheckBox jCheckBox2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel34;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JButton jbEliminaDetalle;
    private javax.swing.JLabel jblCambio;
    private javax.swing.JButton jbtAceptar;
    private javax.swing.JButton jbtAgregar;
    private javax.swing.JComboBox jcbAlmacen;
    private javax.swing.JComboBox jcbEmpresa;
    private javax.swing.JCheckBox jcbProduccion;
    private javax.swing.JComboBox jcbSubAlmacen;
    private javax.swing.JComboBox jcbTipoDocumento;
    private javax.swing.JComboBox jcbTipoIngreso;
    private javax.swing.JComboBox jcbZona;
    private javax.swing.JComboBox jcboMoneda;
    private javax.swing.JLabel jlabelmoneda;
    private javax.swing.JTable jtDetalleSuministro;
    private javax.swing.JTextArea jtaObservacion;
    private javax.swing.JTextField jtfFactura;
    private javax.swing.JFormattedTextField jtfFecha;
    private javax.swing.JTextField jtfMonto;
    public javax.swing.JTextField jtfNumero;
    private javax.swing.JTextField jtfOrden;
    private javax.swing.JTextField jtfProveedor;
    private javax.swing.JTextField jtfRuc;
    public javax.swing.JTextField jtfSerie;
    private javax.swing.JLabel lblProveedor;
    private javax.swing.JTextField txtCambio;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

}
